install.packages(c("tidyverse"))
library(tidyverse)

## Loading economic data
load("retail_sales.RData")
load("farm.RData")
load("banks.RData")

## FIGURE A9 ##
banks = banks %>%
  select(my_fips, bank25:bank36) %>%
  pivot_longer(-my_fips, names_to = "year", values_to = "bank") %>%
  mutate(year = case_when(year == "bank25" ~ "1925",
                          year == "bank26" ~ "1926",
                          year == "bank27" ~ "1927",
                          year == "bank28" ~ "1928",
                          year == "bank29" ~ "1929",
                          year == "bank30" ~ "1930",
                          year == "bank31" ~ "1931",
                          year == "bank32" ~ "1932",
                          year == "bank33" ~ "1933",
                          year == "bank34" ~ "1934",
                          year == "bank35" ~ "1935",
                          year == "bank36" ~ "1936")) %>%
  group_by(year) %>%
  summarise(median_bank = median(bank, na.rm = TRUE)) %>%
  ungroup()

banks <- ggplot(banks, aes(x = factor(year), y = median_bank, group = 1)) +
  geom_bar(stat = "identity", color = "black", fill = "gray", width = 0.8) +
  coord_cartesian(ylim = c(60, 175)) +
  labs(x = "Year",
       y = "Median Bank Deposits") +
  theme_bw() +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"),
        legend.position = "bottom")


## FIGURE A10 ##
## Panel A
retail = retail_sales %>%
  select(my_fips, retail_sales29:retail_sales39) %>%
  pivot_longer(-my_fips, names_to = "year", values_to = "retail") %>%
  mutate(year = case_when(year == "retail_sales29" ~ "1929",
                          year == "retail_sales33" ~ "1933",
                          year == "retail_sales35" ~ "1935",
                          year == "retail_sales39" ~ "1939")) %>%
  group_by(year) %>%
  summarise(median_retail = median(retail, na.rm = TRUE)) %>%
  ungroup()

retail <- ggplot(retail, aes(x = factor(year), y = median_retail, group = 1)) +
  geom_bar(stat = "identity", color = "black", fill = "gray", width = 0.8) +
  coord_cartesian(ylim = c(150, 275)) +
  labs(x = "Year",
       y = "Median Retail Sales") +
  theme_bw() +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"),
        legend.position = "bottom")

## Panel B
farm = farm %>%
  select(my_fips, farm30:farm25) %>%
  pivot_longer(-my_fips, names_to = "year", values_to = "farm") %>%
  mutate(year = case_when(year == "farm30" ~ "1930",
                          year == "farm35" ~ "1935",
                          year == "farm40" ~ "1940",
                          year == "farm25" ~ "1925")) %>%
  group_by(year) %>%
  summarise(median_farm = median(farm, na.rm = TRUE)) %>%
  ungroup()

farm <- ggplot(farm, aes(x = factor(year), y = median_farm, group = 1)) +
  geom_bar(stat = "identity", color = "black", fill = "gray", width = 0.8) +
  coord_cartesian(ylim = c(450, 530)) +
  labs(x = "Year",
       y = "Median Farm Value") +
  theme_bw() +
  theme(panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"),
        legend.position = "bottom")



